package com.egao.common.module.system.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.system.entity.Year;
import com.egao.common.module.system.service.YearService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 毕业年份
 * @author lym
 */
@Api(tags = "毕业年份管理")
@RestController
@RequestMapping("${api}")
public class YearController extends BaseController {

    @Autowired
    private YearService yearService;

    @PreAuthorize("hasAuthority('sys:year:list')")
    @ApiOperation(value = "查询全部毕业年份", notes = "年份倒序")
    @GetMapping("/sys/year/list")
    public JsonResult list() {
        return yearService.listAll();
    }

    @PreAuthorize("hasAuthority('sys:year:insert')")
    @OperLog(value = "毕业年份管理", desc = "新增毕业年份", result = true)
    @ApiOperation("添加毕业年份")
    @PostMapping("/sys/year/insert")
    public JsonResult insert(@RequestBody Year year) {
        return yearService.insertYear(year);
    }

    @PreAuthorize("hasAuthority('sys:year:update')")
    @OperLog(value = "毕业年份管理", desc = "设置毕业年份", result = true)
    @ApiOperation("设置毕业年份")
    @PutMapping("/sys/year/update")
    public JsonResult update(@RequestBody Year year) {
        return yearService.setGraduationYear(year);
    }

}
